package luongvd.weather.model.adapter;

import java.util.ArrayList;

import luongvd.weather.R;
import luongvd.weather.model.object.ObjectCity;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class AdapterCity extends ArrayAdapter<ObjectCity>{

	Activity activity;
	ArrayList<ObjectCity> arrayCity;
	
	public AdapterCity(Activity context, ArrayList<ObjectCity> objects) {
		super(context, R.layout.item_list_name_city, objects);
		this.activity = context;
		this.arrayCity = objects;
	}

	class ViewHolder{
		TextView name_city, tx_status;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null)
		{
			holder = new ViewHolder();
			LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = vi.inflate(R.layout.item_list_name_city, null);
			holder.name_city = (TextView)convertView.findViewById(R.id.name_city);
			holder.tx_status = (TextView)convertView.findViewById(R.id.tx_status);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		ObjectCity objectCity = new ObjectCity();
		objectCity = arrayCity.get(position);
		if(objectCity.getName() != null)
		{
			holder.name_city.setText(objectCity.getName());
		}
		if(objectCity.getDescription() != null){
			holder.tx_status.setVisibility(View.VISIBLE);
			holder.tx_status.setText(objectCity.getDescription());
		}
		
		return convertView;
	}

}
